 /*========================================================================
  Project: 			How Do Patent Incentives Affect University Researchers?
  Date modified:	January 7, 2020
  Author:			Lisa Larrimore Ouellette (SZ modifications)
=========================================================================*/

clear all

********************************************************************************
********************************************************************************

* FIGURE 1

clear
use "AUTM_edited.dta"
drop if id < 2000 /* combined schools, drop here to avoid double counting */
histogram year, discrete frequency fcolor(ebg) lcolor(edkblue)

graph export "Figure1.png", as(png) replace

* Text following Fig 1
summarize invdisrec newpatappfld issuspat grosslicinc legfees reimblegfee ///
	      netlicinc licftes ttoage medsch totresexp

summarize netlicinc
scalar n1 = r(N)
summarize netlicinc if netlicinc < 0
scalar n2 = r(N)
scalar pct =  n2/n1
display pct

* For footnote about 3 data points with net lic income / R&D funding > 1
gen foo = netlicinc/totresexp
summarize foo
tab autm_name foo if foo>1 & foo!=.
tab autm_name year if foo>1 & foo!=.
tab id if foo>1 & foo!=.
scatter totresexp year if (id==95059 | id==95121 | id==95127)

********************************************************************************
********************************************************************************

* FIGURE 2

clear
use "InventorShares_forFig2.dta" /*InventorShares.dta w/ consolidated IDs merged with NRC 1995, NRC 2011, and AUTM data*/
histogram year, discrete frequency fcolor(ebg) lcolor(edkblue)

graph export "Figure2.png", as(png) replace


* Text above and below Fig. 2
clear
use "InventorShares.dta"

	* unique universities
egen x = group(id)
summarize x
egen x2 = group(id) if start <= 2001
summarize x2
egen x3 = group(id) if end < 2001 & x2 !=.
summarize x3
drop x x2 x3
	* number of times there is a change in policy
bysort id : gen freq = _N
tab freq
tab institution if freq==4
tab institution if freq==3
	* number of policies with shares from gross royalties or hybrid
tab institution if gross == 1
tab institution if gross == 0.5
	* unique universities without gross
drop if (gross==1 | gross==0.5)
egen x = group(id)
summarize x
drop x
	* counts of policies with lab and nonlinear increases without gross
tab lab
tab flat lab, missing

********************************************************************************
********************************************************************************

* FIGURES 3A and 3B

	* 3(A)
clear
use "InventorShares_forFig3.dta" /* just "InventorShares_for_figures.dta" */
collapse (mean) mean_share=share (sd) sd_share=share (count) n=share, by(range)
generate hi_share = mean_share + invttail(n-1,0.025)*(sd_share / sqrt(n))
generate lo_share = mean_share - invttail(n-1,0.025)*(sd_share / sqrt(n))
gen labshare = 0
replace labshare = 1 if strpos(range,"lab") != 0
replace range ="0" if range=="s0to10k" | range=="lab0to10k"
replace range ="3" if range=="s10kto50k" | range=="lab10kto50k"
replace range ="6" if range=="s50kto100k" | range=="lab50kto100k"
replace range ="9" if range=="s100kto300k" | range=="lab100kto300k"
replace range ="12" if range=="s300kto500k" | range=="lab300kto500k"
replace range ="15" if range=="s500kto1m" | range=="lab500kto1m"
replace range ="18" if range=="sover1m" | range=="labover1m"
destring(range), replace
gen foo = range + labshare
twoway (bar mean_share foo if labshare==0, fintensity(inten20)) ///
       (bar mean_share foo if labshare==1, fintensity(inten20)) ///
       (rcap hi_share lo_share foo), ///
       legend(row(1) order(1 "inventor share" 2 "lab share") ) ///
	   xlabel(.5 "$0-10k" 3.5 "$10-50k" 6.5 "$50-100k" 9.5 "$100-300k" 12.5 "$300-500k" 15.5 "$500k-1M" 18.5 ">$1M", noticks) ///
       yscale(range(0 0.6)) ylabel(0 (0.2) 0.6) ytitle("mean royalty share") xtitle("") ///
       title("(A) All Policies Combined")

graph export "Figure3A.png", as(png) replace

	* 3(B)
clear
use "InventorShares_forFig3.dta" /* just "InventorShares_for_figures.dta" */
drop if flat==1
collapse (mean) mean_share=share (sd) sd_share=share (count) n=share, by(range)
generate hi_share = mean_share + invttail(n-1,0.025)*(sd_share / sqrt(n))
generate lo_share = mean_share - invttail(n-1,0.025)*(sd_share / sqrt(n))
gen labshare = 0
replace labshare = 1 if strpos(range,"lab") != 0
replace range ="0" if range=="s0to10k" | range=="lab0to10k"
replace range ="3" if range=="s10kto50k" | range=="lab10kto50k"
replace range ="6" if range=="s50kto100k" | range=="lab50kto100k"
replace range ="9" if range=="s100kto300k" | range=="lab100kto300k"
replace range ="12" if range=="s300kto500k" | range=="lab300kto500k"
replace range ="15" if range=="s500kto1m" | range=="lab500kto1m"
replace range ="18" if range=="sover1m" | range=="labover1m"
destring(range), replace
gen foo = range + labshare
twoway (bar mean_share foo if labshare==0, fintensity(inten20)) ///
       (bar mean_share foo if labshare==1, fintensity(inten20)) ///
       (rcap hi_share lo_share foo), ///
       legend(row(1) order(1 "inventor share" 2 "lab share") ) ///
       xlabel(.5 "$0-10k" 3.5 "$10-50k" 6.5 "$50-100k" 9.5 "$100-300k" 12.5 "$300-500k" 15.5 "$500k-1M" 18.5 ">$1M", noticks) ///
       ytitle("mean royalty share") xtitle("") ///
       title("(B) Only Policies with Nonlinear Schedules")

graph export "Figure3B.png", as(png) replace

********************************************************************************
********************************************************************************

* FIGURES 4A and 4B

	* 4(A)
clear
use "InventorShares_forFig4.dta" /* "InventorShares_forFig3.dta" expanded for 1991 - 2017 within policy years */
collapse (mean) mean_share=share (sd) sd_share=share (count) n=share, by(range year)
generate hi_share = mean_share + invttail(n-1,0.025)*(sd_share / sqrt(n))
generate lo_share = mean_share - invttail(n-1,0.025)*(sd_share / sqrt(n))
twoway (line mean_share year if range=="s0to10k", lpattern(dash)) ///
       (line mean_share year if range=="s10kto50k", lpattern(dot)) ///
       (line mean_share year if range=="s50kto100k", lpattern(longdash)) ///
       (line mean_share year if range=="s100kto300k", lpattern(shortdash_dot)) ///
       (line mean_share year if range=="s300kto500k", lpattern(shortdash)) ///
       (line mean_share year if range=="s500kto1m", lpattern("-..")) ///
       (line mean_share year if range=="sover1m", lpattern("_--")), ///
       xscale(range(1991 2017)) xlabel(1991 (4) 2017) ///
       yscale(range(0.3 0.6)) ylabel(0.3 (0.1) 0.6) ytitle("mean inventor share") ///
       legend(order(1 "$0-10k" 2 "$10k-50k" 3 "$50k-100k" 4 "$100k-300k" 5 "$300k-500k" 6 "$500k-1M" 7 ">$1M")) ///
       title("(A) All Policies")

graph export "Figure4A.png", as(png) replace
	   
	* 4(B)
clear
use "InventorShares_forFig4.dta" /* "InventorShares_forFig3.dta" expanded for 1991 - 2017 within policy years */
drop if flat==1 & range!="s0to10k"
collapse (mean) mean_share=share (sd) sd_share=share (count) n=share, by(range year flat)
twoway (line mean_share year if range=="s0to10k" & flat==0, lpattern(dash)) ///
       (line mean_share year if range=="s10kto50k" & flat==0, lpattern(dot)) ///
       (line mean_share year if range=="s50kto100k" & flat==0, lpattern(longdash)) ///
       (line mean_share year if range=="s100kto300k" & flat==0, lpattern(shortdash_dot)) ///
       (line mean_share year if range=="s300kto500k" & flat==0, lpattern(shortdash)) ///
       (line mean_share year if range=="s500kto1m" & flat==0, lpattern("-..")) ///
       (line mean_share year if range=="sover1m" & flat==0, lpattern("_--")) ///
       (line mean_share year if flat==1, lpattern(solid) lcolor(black)), ///
       xscale(range(1991 2017)) xlabel(1991 (4) 2017) ///
       yscale(range(0.3 0.6)) ylabel(0.3 (0.1) 0.6) ytitle("mean inventor share") ///
       legend(order(1 "$0-10k" 2 "$10k-50k" 3 "$50k-100k" 4 "$100k-300k" 5 "$300k-500k" 6 "$500k-1M" 7 ">$1M" 8 "linear policies")) ///
       title("(B) Separating Linear and Nonlinear Policies")
	   
graph export "Figure4B.png", as(png) replace
	   
* just for textual claims above Figure 4B
twoway (line sd_share year if range=="s0to10k" & flat==0) ///
       (line sd_share year if range=="s10kto50k" & flat==0) ///
       (line sd_share year if range=="s50kto100k" & flat==0) ///
       (line sd_share year if range=="s100kto300k" & flat==0) ///
       (line sd_share year if range=="s300kto500k" & flat==0) ///
       (line sd_share year if range=="s500kto1m" & flat==0) ///
       (line sd_share year if range=="sover1m" & flat==0) ///
       (line sd_share year if flat==1), ///
       xscale(range(1991 2017)) xlabel(1991 (4) 2017) ///
       yscale(range(0.06 0.2)) ytitle("mean inventor share") ///
       legend(order(1 "$0-10k" 2 "$10k-50k" 3 "$50k-100k" 4 "$100k-300k" 5 "$300k-500k" 6 "$500k-1M" 7 ">$1M" 8 "linear policies")) ///
       title("(B) Separating Linear and Nonlinear Policies")
	   
********************************************************************************
********************************************************************************

* FIGURE 5

clear
use "AUTM_edited_forFig5.dta" /* "AUTM_edited.dta" with a range of values ("x") for kernel density */
gen netlicincperdisc = netlicinc/invdisrec
gen netlicincperapp = netlicinc/newpatappfld
gen netlicincperpat = netlicinc/issuspat
kdensity netlicincperdisc if year<1999, at(x) gen(x1 fx1) nograph
kdensity netlicincperdisc if year>=1999, at(x) gen(x2 fx2) nograph
kdensity netlicincperapp if year<1999, at(x) gen(x3 fx3) nograph
kdensity netlicincperapp if year>=1999, at(x) gen(x4 fx4) nograph
kdensity netlicincperpat if year<1999, at(x) gen(x5 fx5) nograph
kdensity netlicincperpat if year>=1999, at(x) gen(x6 fx6) nograph
drop x1 x2 x3 x4 x5 x6
replace x=. if x<-45000 | x>200000
twoway (line fx1 x, lpattern(solid) lcolor(ebblue)) ///
	   (line fx2 x, lpattern(shortdash)) ///
	   (line fx3 x, lpattern(dash)) ///
	   (line fx4 x, lpattern(dot)) ///
	   (line fx5 x, lpattern(shortdash_dot)) ///
	   (line fx6 x, lpattern("_--")), ///
  yscale(range(0 0.000034)) ylabel (0 (0.00001) 0.000034) ytitle("kernel density") ///
  xtitle("net license income per disclosure / patent app / issued patent") ///
  legend(order(1 "per disclosure 1991-99" 2 "per disclosure 2000-13" 3 "per patent app 1991-99" 4 "per patent app 2000-13" 5 "per iss patent 1991-99" 6 "per iss patent 2000-13"))
  
graph export "Figure5.png", as(png) replace

********************************************************************************
********************************************************************************

* TABLE 2

	* see "kernel integration.xlsx"
	* integrates over estimated kernel density function in Figure 5 from a to b using the formula (b-a)*[(f(a)+f(b))/2)]
	* Then sums the results over each segment to derive the cumulative distribution

* Text after Table 2
clear
use "AUTM_edited_forFig5.dta" /* "AUTM_edited.dta" with a range of values ("x") for kernel density */
gen netlicincperdisc = netlicinc/invdisrec
summarize netlicincperdisc if id == 95165 /*Stanford */
summarize netlicincperdisc if id == 95060 /* FL Atlantic */
summarize netlicinc
summarize netlicinc if netlicinc < 0

* Text on overhead fees after Table 2
clear
use "InventorShares.dta"
summarize adminfee if gross == .

********************************************************************************
********************************************************************************

* FIGURE 6 (Cf. L&S2004 Fig 1) 

clear
use "Merged_1991-99_avg.dta"
	* 6(A)
histogram combinedshare_LS, frequency width(0.05) start(.175) fcolor(ebg) lcolor(edkblue) xscale(range(.2 .8)) xlabel(.2 (.2) .8) xtitle("Combined share with L&S weighting (N=125)")
graph export "Figure6A.png", as(png) replace
	* 6(B)
histogram inventorshare_LS, frequency width(0.05) start(.175) fcolor(ebg) lcolor(edkblue) xscale(range(.2 .8)) xlabel(.2 (.2) .8) xtitle("Personal share with L&S weighting (N=125)")
graph export "Figure6B.png", as(png) replace
	* 6(C)
histogram combinedshare_LS if flat==1, frequency width(0.05) start(.175) fcolor(ebg) lcolor(edkblue) xscale(range(.2 .8)) xlabel(.2 (.2) .8) xtitle("Combined share with only linear policies (N=82)")
graph export "Figure6C.png", as(png) replace
	* 6(D)
histogram inventorshare_LS if flat==1, frequency width(0.05) start(.175) fcolor(ebg) lcolor(edkblue) xscale(range(.2 .8)) xlabel(.2 (.2) .8) xtitle("Personal share with only linear policies (N=82)")
graph export "Figure6D.png", as(png) replace
	* 6(E)
histogram combinedshare_LSnofee, frequency width(0.05) start(.175) fcolor(ebg) lcolor(edkblue) xscale(range(.2 .8)) xlabel(.2 (.2) .8) xtitle("Combined share, L&S weighting, no overhead correction (N=125)")
graph export "Figure6E.png", as(png) replace
	*6(F)
histogram inventorshare_LSnofee, frequency width(0.05) start(.175) fcolor(ebg) lcolor(edkblue) xscale(range(.2 .8)) xlabel(.2 (.2) .8) xtitle("Personal share, L&S weighting, no overhead correction (N=125)")
graph export "Figure6F.png", as(png) replace

********************************************************************************
********************************************************************************

* TABLE 3 (Cf. L&S2004 Table 3)

clear
use "Merged_1991-99_avg.dta"
gen resexp_millions = avgtotresexp/1000000
gen combinedshare_LS_100 = combinedshare_LS*100
gen inventorshare_LSnofee_100 = inventorshare_LSnofee*100
reg combinedshare_LS_100 faculty00s quality private pubs cites ///
    biomedical otherbiological computerscience chemicalscience engineering, robust
outreg2 using "outreg3.doc", replace
reg combinedshare_LS_100 faculty00s quality private ///
    biomedical otherbiological computerscience chemicalscience engineering resexp_millions avglicftes avgttoage, robust
outreg2 using "outreg3.doc", append
reg inventorshare_LSnofee_100 faculty00s quality private pubs cites ///
    biomedical otherbiological computerscience chemicalscience engineering, robust
outreg2 using "outreg3.doc", append
reg inventorshare_LSnofee_100 faculty00s quality private ///
    biomedical otherbiological computerscience chemicalscience engineering resexp_millions avglicftes avgttoage, robust
outreg2 using "outreg3.doc", append

********************************************************************************
********************************************************************************

** 4.2 CROSS-SECTIONAL RESULTS

********************************************************************************
********************************************************************************

* TABLE 4 (Cf. L&S2004 Table 4)

clear
use "Merged_1991-99_avg.dta"
reg lnavgnetlicinc combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
outreg2 using "outreg4.doc", replace
reg lnavgnetlicinc combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg4.doc", append
reg lnavgnetlicinc inventorshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
outreg2 using "outreg4.doc", append
reg lnavgnetlicinc inventorshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg4.doc", append

********************************************************************************
********************************************************************************

* TABLE 5

clear
use "Merged_1991-99_avg.dta"
	*row 1
reg lnavgnetlicinc combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
	*row 2
reg lnavgnetlicinc inventorshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc inventorshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
	*row 3
reg lnavgnetlicinc combinedshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc combinedshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
	*row 4
reg lnavgnetlicinc inventorshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc inventorshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
	*row 5
reg lnavgnetlicinc combinedshare_1st3 lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc combinedshare_1st3 lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
   *row 6
reg lnavgnetlicinc inventorshare_1st3 lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc inventorshare_1st3 lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
   *row 7
reg lnavgnetlicinc combinedshare_1st4 lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc combinedshare_1st4 lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
   *row 8
reg lnavgnetlicinc inventorshare_1st4 lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc inventorshare_1st4 lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust

drop if flat==0
	*row 9
reg lnavgnetlicinc combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
   *row 10
reg lnavgnetlicinc inventorshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc inventorshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
   *row 11
reg lnavgnetlicinc combinedshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc combinedshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
   *row 12
reg lnavgnetlicinc inventorshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering, robust
reg lnavgnetlicinc inventorshare_LSnofee lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust

********************************************************************************
********************************************************************************

* TABLE 6 (other dependent variables)

clear
use "Merged_1991-99_avg.dta"
reg avginvdisres combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg6.doc", replace
reg avgnewpatappfld combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg6.doc", append
reg avgissuspat combinedshare_LS lnfaculty quality private ///
   biomedical otherbiological computerscience chemicalscience engineering lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg6.doc", append

********************************************************************************
********************************************************************************

* TABLE 7 (other dependent variables)

clear
use "Merged_2000-13_avg.dta"
reg avginvdisres combinedshare_LS lnfaculty2 cites2 private ///
   biomedical2 otherbiological2 computerscience2 chemicalscience2 engineering2 lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg7.doc", replace
reg avgnewpatappfld combinedshare_LS lnfaculty2 cites2 private ///
   biomedical2 otherbiological2 computerscience2 chemicalscience2 engineering2 lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg7.doc", append
reg avgissuspat combinedshare_LS lnfaculty2 cites2 private ///
   biomedical2 otherbiological2 computerscience2 chemicalscience2 engineering2 lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg7.doc", append
reg lnavgnetlicinc combinedshare_LS lnfaculty2 cites2 private ///
   biomedical2 otherbiological2 computerscience2 chemicalscience2 engineering2 lnavgtotresexp avglicftes avgttoage, robust
outreg2 using "outreg7.doc", append

********************************************************************************
********************************************************************************

** 4.3 PANEL DATA RESULTS

********************************************************************************
********************************************************************************

* TABLE 8 (fixed effects)

clear
use "Merged_byyear.dta"
xtset id year

/* ssc install reghdfe
ssc install ftools
reghdfe, compile */

	* 8(A)
reghdfe invdisrec combinedshare_LS, absorb (year id) vce(cluster id)
reghdfe newpatappfld combinedshare_LS, absorb (year id) vce(cluster id)
reghdfe issuspat l3.combinedshare_LS, absorb (year id) vce(cluster id)

	* Similar results if add 2-yr lag to Table 8(A)
reghdfe invdisrec l2.combinedshare_LS, absorb (year id) vce(cluster id)
reghdfe newpatappfld l2.combinedshare_LS, absorb (year id) vce(cluster id)
reghdfe issuspat l5.combinedshare_LS, absorb (year id) vce(cluster id)

	* 8(B)
reghdfe discperfaculty2 combinedshare_LS, absorb (year id) vce(cluster id)
reghdfe appperfac2 combinedshare_LS, absorb (year id) vce(cluster id)
reghdfe issperfac2 l3.combinedshare_LS, absorb (year id) vce(cluster id)

	* 8(C)
summarize faculty2, detail
scalar fac_median = r(p50)
drop if faculty2 < fac_median

reghdfe discperfaculty2 combinedshare_LS, absorb (year id) vce(cluster id)
reghdfe appperfac2 combinedshare_LS, absorb (year id) vce(cluster id)
reghdfe issperfac2 l3.combinedshare_LS, absorb (year id) vce(cluster id)

********************************************************************************
********************************************************************************

** 4.5 MOVES BETWEEN UNIVERSITIES BY ACTIVE PATENTERS

********************************************************************************
********************************************************************************

* FIGURE 7

clear
use "Superpatenters_forFig7" /* just "Superpatenters_edited.dta" */
histogram combinedshare_diff, frequency width(0.05) start(-.625) ///
	      fcolor(ebg) lcolor(edkblue) xtitle("Difference in Combined Share Between New and Old University")

graph export "Figure7.png", as(png) replace

* Text before figure 7
clear
use "Superpatenters.dta"
tab lateral

clear
use "Superpatenters_forFig7" /* just "Superpatenters_edited.dta", replace */
summarize combinedshare_diff
summarize combinedshare_diff if combinedshare_diff>0
summarize combinedshare_diff if combinedshare_diff<0
summarize combinedshare_diff if combinedshare_diff==0
summarize combinedshare_diff if patents10>30


********************************************************************************
********************************************************************************

** 4.1.5 ROBUSTNESS CHECK

********************************************************************************
********************************************************************************

* For support for "we do not see any striking dips or increases in our ///
* outcome variables of interest just prior to changes in university ///

clear
use "policy_changes_robust.dta"
		
/* ------------------
     1) Disclosure 
--------------------*/

 twoway (connect disclosure ytochange if firstchange_pos == 0, lwidth(medium) msymbol(circle) lcolor(edkblue) mcolor(edkblue)) ///
		(connect uci_disclosure ytochange if firstchange_pos == 0, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(emidblue) mcolor(emidblue)) ///
		(connect lci_disclosure ytochange if firstchange_pos == 0, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(emidblue) mcolor(emidblue)), ///
		xline(0, lcolor(red)) ///	
		xscale(range(-10(5)10)) ///
		xlabel(-10(5)10) ///
		xtitle("Years to decrease", size(medium)) ///
		yscale(range(-50 150)) ///
		ylabel(0(50)150) ///
		title("Disclosures among universities that{it: decreased} their sharing rate", size(medlarge)) ///
		legend(off) ///
		saving("policy_changes_disclosures_decrease.gph",  replace) 
 graph export "policy_changes_disclosures_decrease.png", as(png) replace	

 twoway (connect disclosure ytochange if firstchange_pos == 1, lwidth(medium) msymbol(circle) lcolor(edkblue) mcolor(edkblue)) ///
		(connect uci_disclosure ytochange if firstchange_pos == 1, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(emidblue) mcolor(emidblue)) ///
		(connect lci_disclosure ytochange if firstchange_pos == 1, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(emidblue) mcolor(emidblue)), ///
		xline(0, lcolor(red)) ///	
		xscale(range(-10(5)10)) ///
		xlabel(-10(5)10) ///
		yscale(range(-50 150)) ///
		ylabel(0(50)150) ///
		xtitle("Years to increase", size(medium)) ///
		legend(off) ///
		title("Disclosures among universities that{it: increased} their sharing rate", size(medlarge)) ///
		saving("policy_changes_disclosures_increase.gph", replace)
 graph export "policy_changes_disclosures_increase.png", as(png) replace	


/* ------------------
    2) Log income
--------------------*/

 twoway (connected lnincome ytochange if firstchange_pos == 0, lwidth(medium) msymbol(circle) lcolor(edkblue) mcolor(edkblue)) ///
		(connect uci_lnincome ytochange if firstchange_pos == 0, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(edkblue) mcolor(edkblue)) ///
		(connect lci_lnincome ytochange if firstchange_pos == 0, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(edkblue) mcolor(edkblue)), ///
		xline(0, lcolor(red)) ///	
		xscale(range(-10(5)10)) ///
		xlabel(-10(5)10) ///
		yscale(range(-40 90)) ///
		ylabel(-40(20)80) ////
		xtitle("Years to decrease", size(medium)) ///
		title("Log income among universities that{it: decreased} their sharing rate", size(medlarge)) ///
		legend(off) ///
		saving("policy_changes_lnincome_decrease.gph", replace) 
graph export "policy_changes_lnincome_decrease.png", as(png) replace	

 twoway (connected lnincome ytochange if firstchange_pos == 1, lwidth(medium) msymbol(circle) lcolor(edkblue) mcolor(edkblue)) ///
		(connect uci_lnincome ytochange if firstchange_pos == 1, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(edkblue) mcolor(edkblue)) ///
		(connect lci_lnincome ytochange if firstchange_pos == 1, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(edkblue) mcolor(edkblue)), ///
		xline(0, lcolor(red)) ///	
		xscale(range(-10(5)10)) ///
		xlabel(-10(5)10) ///
		yscale(range(-40 90)) ///
		ylabel(-40(20)80) ////
		xtitle("Years to increase", size(medium)) ///
		title("Log income among universities that{it: increased} their sharing rate", size(medlarge)) ///
		legend(off) ///
		saving("policy_changes_lnincome_increase.gph", replace)
graph export "policy_changes_lnincome_increase.png", as(png) replace	


/* ------------------
   3) New Applications 
--------------------*/

 twoway (connected newpatentapp ytochange if firstchange_pos == 0, lwidth(medium) msymbol(circle)  lcolor(edkblue) mcolor(edkblue)) ///
		(connect uci_newpatentapp ytochange if firstchange_pos == 0, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(edkblue) mcolor(edkblue)) ///
		(connect lci_newpatentapp ytochange if firstchange_pos == 0, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(edkblue) mcolor(edkblue)), ///
		xline(0, lcolor(red)) ///
		xscale(range(-10(5)10)) ///
		xlabel(-10(5)10) ///
		xtitle("Years to decrease", size(medium)) ///
		title("New patent applications among universities" "that{it: decreased} their sharing rate", size(medlarge) linegap(2)) ///
		legend(off) ///
		saving("policy_changes_apps_decrease.gph", replace) 
graph export "policy_changes_apps_decrease.png", as(png) replace	

		
 twoway (connected newpatentapp ytochange if firstchange_pos == 1, lwidth(medium) msymbol(circle) lcolor(edkblue) mcolor(edkblue)) ///
		(connect uci_newpatentapp ytochange if firstchange_pos == 1, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(edkblue) mcolor(edkblue)) ///
		(connect lci_newpatentapp ytochange if firstchange_pos == 1, msymbol(circle_hollow) lpattern(dash) lwidth(thin) lcolor(edkblue) mcolor(edkblue)), ///
		xline(0, lcolor(red)) ///
		xscale(range(-10(5)10)) ///
		xlabel(-10(5)10) ///
		xtitle("Years to increase", size(medium)) ///
		title("New patent applications among universities" "that{it: increased} their sharing rate", size(medlarge) linegap(2)) ///
		legend(off) ///
		saving("policy_changes_apps_increase.gph", replace) 
graph export "policy_changes_apps_increase.png", as(png) replace	



